package com.example.demo.Filter.InterceptorConfig;

import com.example.demo.Filter.JWTInterceptors.JWTInterceptors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;
import java.util.List;

@Configuration
@Slf4j
public class InterceptorConfig implements WebMvcConfigurer {
    @Bean
    public JWTInterceptors myInterceptor() {
        return new JWTInterceptors();
    }

    private static final List<String> EXCLUDED_PATHS = Arrays.asList(
            "/login",
            "/static/**",
            "/index",
            "/user/SinIn",
            "/user/logout",
            "/userinfo/register",
            "/upload",
            "/user",
            "/img/**",
            "/favicon.ico",
            "/md",
            "/swagger-ui/**",
            "/user/getToken",
            "/v3/**",
            "/swagger-resources/**",
            "/swagger-ui.html",
            "/webjars/**",
            "/doc/**",
            "/Page/**"
    );

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        log.info("白名单配置完毕");
        registry.addInterceptor(myInterceptor())
                .excludePathPatterns(EXCLUDED_PATHS);
    }
}
